﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using geetol.sms.core;

namespace geetol.sms.service.task
{
    public abstract class taskBase
    {
        bool isRun = false;

        protected Logs log;

        protected int runSleep = 10000;
        protected int invalidTime = 60;

        public taskBase()
        {
            log = new Logs(this.GetType().Name);
            var c = config.LoadSendConfig();
            runSleep = c.sendsleep * 1000;
            invalidTime = c.invalidtime;
            Run();
        }

        protected void Run()
        {
            if (isRun) return;
            isRun = true;
            log.Write("开始启动");
            new Thread(new ThreadStart(() =>
            {
                Thread.Sleep(runSleep);
                while (Service1.isStart)
                {
                    PerformTasks();
                    Thread.Sleep(runSleep);
                }

            }))
            { IsBackground = true }.Start();
        }

        protected abstract void PerformTasks();
    }
}
